from flask import Flask, request, jsonify
import hashlib  # 用于密码加密

app = Flask(__name__)


@app.route('/api', methods=['POST'])
def register():
    data = request.get_json()
    if not data:
        return jsonify({"error": "No input data provided"}), 400
    username = data.get('username')
    password = data.get('password')
    phone = data.get('phone')

    if not username or not password or not phone:
        return jsonify({"error": "Username, password, and email are required"}), 400

    # 简单的密码加密示例，实际应用中应使用更安全的方式
    # hashed_password = hashlib.sha256(password.encode()).hexdigest()

    # 这里可以添加将用户信息保存到数据库的逻辑
    # 示例：假设数据库操作函数为save_user_to_db
    # save_user_to_db(username, hashed_password, email)

    return jsonify({"status": "success", "message": "User registered successfully"}), 201


if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=True)